const express = require('express')

const app = express()

app.use(express.static('public'))

app.listen(3000, () => {
  console.log('success')
})


/***********************************************/

var proxy = require('http-proxy-middleware')
 
// proxy middleware options
var options = {
  target: 'http://www.kongfz.com', // target host
  changeOrigin: true, // needed for virtual hosted sites
  ws: true, // proxy websockets
  pathRewrite: {
    '^/api': '/', // rewrite path
  },
  router: {
    // when request.headers.host == 'dev.localhost:3000',
    // override target 'http://www.example.org' to 'http://localhost:8000'
    'dev.localhost:3000': 'http://localhost:8000'
  }
}

// create the proxy (without context)
var exampleProxy = proxy(options)
 
// mount `exampleProxy` in web server
app.use('/api', exampleProxy)

